﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;
using System.Configuration;

namespace CashDifferenceReportApp
{
    public partial class NewPrinter : Form
    {
        PaperSize psize;
        string branch = string.Empty;
        string date = string.Empty;

        public NewPrinter(string branch, string dt)
        {
            this.branch = branch;
            date = dt;
            InitializeComponent();
        }

        private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.PageSettings.PaperSize = psize;
            e.Graphics.DrawString("KS BAKERS", new Font(new FontFamily("Times New Roman"), 12, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 100, -3);

            int lineCounter = 15;

            e.Graphics.DrawString("CASH DIFFERENCE REPORT", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(branch.ToUpper() + "          " + date, new Font(new FontFamily("Times New Roman"), 9, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter += 15);

            lineCounter += 7;

            e.Graphics.DrawString("-------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 47, lineCounter);
            
            lineCounter += 15;
            e.Graphics.DrawString("Cake Sales", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            e.Graphics.DrawString(Storage.CakeSales.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

            lineCounter += 15;
            e.Graphics.DrawString("Cake Advances", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            e.Graphics.DrawString(Storage.CakeAdvances.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
            
            lineCounter += 15;
            e.Graphics.DrawString("Ideal Balances", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            e.Graphics.DrawString(Storage.CakeIdealBalances.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

            lineCounter += 15;
            e.Graphics.DrawString("Actual Balances", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            e.Graphics.DrawString(Storage.CakeActualBalances.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

            lineCounter += 15;
            e.Graphics.DrawString("Discount", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            e.Graphics.DrawString(Storage.Discount.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

            lineCounter += 15;
            e.Graphics.DrawString("Bulk Orders", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            e.Graphics.DrawString(Storage.BulkOrders.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

            lineCounter += 15;
            e.Graphics.DrawString("Expenses", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            e.Graphics.DrawString(Storage.Expenses.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

            lineCounter += 15;
            e.Graphics.DrawString("Sodexho Sales", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            e.Graphics.DrawString(Storage.SodexhoSales.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

            lineCounter += 15;
            e.Graphics.DrawString("Card Sales", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            e.Graphics.DrawString(Storage.CardSales.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

            lineCounter += 15;
            e.Graphics.DrawString("Adv/Bills", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            e.Graphics.DrawString(Storage.EmpAdvanceAndBillAmounts.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

            lineCounter += 15;
            e.Graphics.DrawString("Credit Note", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            e.Graphics.DrawString(Storage.CreditNoteAmount.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

            //lineCounter += 15;
            //e.Graphics.DrawString("Cash Available", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
            //e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
            //e.Graphics.DrawString(Storage.CashAvailable.ToString("c"), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

            lineCounter += 7;
            e.Graphics.DrawString("-------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 47, lineCounter);
            lineCounter += 15;

            //Cashier Wise Sales
            foreach (DataGridViewRow row in Storage.CashierGrid.Rows)
            {
                //Cashier
                if (row.Cells[1].Value.ToString() != "Cake Sales" && row.Cells[1].Value.ToString() != "Bulk Sales")
                {
                    e.Graphics.DrawString("Cashier", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[1].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Discounts", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[3].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Cake Advances", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[4].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Cake Discounts", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[5].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Cake Balances", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[6].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("BO Advances", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[7].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("BO Balances", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[8].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Expenses", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[9].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Sodexho", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[10].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Credit Card", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[11].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Adv/Bills", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[12].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Cash Available", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[13].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Cash In Hand", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[14].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Difference", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[15].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

                    lineCounter += 10;
                    e.Graphics.DrawString("-------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 47, lineCounter);

                    lineCounter += 15;
                }
                else if (row.Cells[1].Value.ToString() == "Cake Sales" || row.Cells[1].Value.ToString() == "Bulk Sales")
                {
                    e.Graphics.DrawString(row.Cells[1].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Discounts", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[3].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Amount", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[11].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Cash In Hand", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[12].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);
                    lineCounter += 15;

                    e.Graphics.DrawString("Difference", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 50, lineCounter);
                    e.Graphics.DrawString(":", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 140, lineCounter);
                    e.Graphics.DrawString(row.Cells[13].Value.ToString(), new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 150, lineCounter);

                    lineCounter += 10;
                    e.Graphics.DrawString("-------------------------------------------", new Font(new FontFamily("Times New Roman"), 10, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 47, lineCounter);

                    lineCounter += 15;
                }
            }

            e.Graphics.DrawString("Generated On " + DateTime.Now.ToString("dd-MMM-yyyy hh:mm tt"), new Font(new FontFamily("Times New Roman"), 8, System.Drawing.FontStyle.Regular), System.Drawing.Brushes.Black, 60, lineCounter);
        }

        private void printDocument1_QueryPageSettings(object sender, System.Drawing.Printing.QueryPageSettingsEventArgs e)
        {
            int noOfCashiers = Storage.CashierGrid.Rows.Count - 1;
            //psize = new PaperSize("name", 300, 200 + (150 * noOfCashiers) + (115 * 2) + 250);
            psize = new PaperSize("name", 300, 200 + (200 * noOfCashiers) + (115 * 2) + 100);
            e.PageSettings.PaperSize = psize;
        }
    }
}
